/**
 * 资源相关接口
 */

/**
 * 导入字体资源
 */
export const IMPORT_RESOURCE_FONT = 'IMPORT_RESOURCE_FONT'

/**
 * 导入图片资源
 */
export const IMPORT_RESOURCE_IMAGE = 'IMPORT_RESOURCE_IMAGE'

/**
 * 导入音频资源
 */
export const IMPORT_RESOURCE_AUDIO = 'IMPORT_RESOURCE_AUDIO'

/**
 * 导入视频资源
 */
export const IMPORT_RESOURCE_VIDEO = 'IMPORT_RESOURCE_VIDEO'

/**
 * 导入GIF资源
 */
export const IMPORT_RESOURCE_GIF = 'IMPORT_RESOURCE_GIF'


/**
 * 加载字体资源完成
 */
export const LOAD_RESOURCE_GIF_COMPLETE = 'LOAD_RESOURCE_GIF_COMPLETE'

/**
 * 加载字体资源完成
 */
export const LOAD_RESOURCE_FONT_COMPLETE = 'LOAD_RESOURCE_FONT_COMPLETE'

/**
 * 加载图片资源完成
 */
export const LOAD_RESOURCE_IMAGE_COMPLETE = 'LOAD_RESOURCE_IMAGE_COMPLETE'

/**
 * 加载音频资源完成
 */
export const LOAD_RESOURCE_AUDIO_COMPLETE = 'LOAD_RESOURCE_AUDIO_COMPLETE'

/**
 * 加载视频资源完成
 */
export const LOAD_RESOURCE_VIDEO_COMPLETE = 'LOAD_RESOURCE_VIDEO_COMPLETE'

/**
 * 刷新资源
 */
export const REFRESH_RESOURCE = 'REFRESH_RESOURCE'

/**
 * 刷新资源完成
 */
export const REFRESH_RESOURCE_COMPLETE = 'REFRESH_RESOURCE_COMPLETE'

/**
 * 删除资源
 */
export const DELETE_RESOURCE = 'DELETE_RESOURCE'

/**
 * 根据资源名称删除资源
 */
export const DELETE_RESOURCE_BY_NAME = 'DELETE_RESOURCE_BY_NAME'

/**
 * 根据资源名称删除资源结果
 */
export const DELETE_RESOURCE_BY_NAME_RESULT = 'DELETE_RESOURCE_BY_NAME_RESULT'

/**
 * 替换图片资源
 */
export const REPLACE_RESOURCE_IMAGE = 'REPLACE_RESOURCE_IMAGE'

export const REPLACE_RESOURCE_GIF = 'REPLACE_RESOURCE_GIF'

export default (resourceEmitter) => {
  /**
   * 导入字体资源
   */
  resourceEmitter.on(IMPORT_RESOURCE_FONT, () => {
    window.api.SendImportFont()
  })

  /**
   * 导入图片资源
   */
  resourceEmitter.on(IMPORT_RESOURCE_IMAGE, () => {
    window.api.SendImportImage()
  })


  /**
   * 导入图片资源
   */
  resourceEmitter.on(IMPORT_RESOURCE_GIF, () => {
    window.api.SendImportGif()
  })


  /**
   * 导入音频资源
   */
  resourceEmitter.on(IMPORT_RESOURCE_AUDIO, () => {
    window.api.SendImportAudio()
  })

  /**
   * 导入视频资源
   */
  resourceEmitter.on(IMPORT_RESOURCE_VIDEO, () => {
    window.api.SendImportVideo()
  })

  /**
   * 监听到字体加载完成
   */
  window.api.OnLoadFont((fontList) => {
    resourceEmitter.emit(LOAD_RESOURCE_FONT_COMPLETE, fontList)
  })

  /**
   * 监听到图片加载完成
   */
  window.api.OnLoadImage((imageList) => {
    resourceEmitter.emit(LOAD_RESOURCE_IMAGE_COMPLETE, imageList)
  })

  window.api.OnLoadGif((imageList) => {
    resourceEmitter.emit(LOAD_RESOURCE_GIF_COMPLETE, imageList)
  })

  /**
   * 监听到音频加载完成
   */
  window.api.OnLoadAudio((audioList) => {
    resourceEmitter.emit(LOAD_RESOURCE_AUDIO_COMPLETE, audioList)
  })

  /**
   * 监听到视频加载完成
   */
  window.api.OnLoadVideo((videoList) => {
    resourceEmitter.emit(LOAD_RESOURCE_VIDEO_COMPLETE, videoList)
  })

  /**
   * 刷新资源
   */
  resourceEmitter.on(REFRESH_RESOURCE, () => {
    const resources = window.api.SendRefreshResource()
    resourceEmitter.emit(REFRESH_RESOURCE_COMPLETE, resources)
  })

  /**
   * 删除资源
   */
  resourceEmitter.on(DELETE_RESOURCE, (type) => {
    window.api.SendDeleteResource(type)
  })

  /**
   * 根据资源名称删除资源
   */
  resourceEmitter.on(DELETE_RESOURCE_BY_NAME, (name) => {
    const result = window.api.SendDeleteFile(name)
    resourceEmitter.emit(DELETE_RESOURCE_BY_NAME_RESULT, { name, result })
  })

  /**
   * 替换图片资源
   */
  resourceEmitter.on(REPLACE_RESOURCE_IMAGE, (name) => {
    window.api.SendRepalcePng(name)
  })

  resourceEmitter.on(REPLACE_RESOURCE_GIF, (name) => {
    window.api.SendRepalceGif(name)
  })
}
